import { GCtrl } from "../../lib/util/GCtrl";

const { ccclass, property } = cc._decorator;
/** 修改昵称 create by tm */
@ccclass
export default class DWC_ChangeNick extends cc.Component {

    @property(cc.EditBox)
    edtBox_nick: cc.EditBox = null;

    changenick: string = null;
    
    onClickBack(): void {
        GCtrl.UIMgr.close(GCtrl.GLConfig.DWC_ChangeNick_path, GCtrl.UIMgr.closeType.hide);
        cc.vv.audioUtil.playSound("/Hall/sound/button_onclicked");
    }
    /** 确定修改昵称 */
    sureChangeNick(): void {
        if (!this.edtBox_nick) return;
        //修改昵称
        let _nick: string = this.edtBox_nick.string;
        if (!_nick) return;
        GCtrl.GLUtils.sendRequest(`ChangeRolename`, {
            rolename: _nick
        }, (_err, _data) => {
            if (_data.errcode)
                GCtrl.GLUtils.showTips(_data.errdesc);
            else {
                GCtrl.session.setRoleName(_nick);
                GCtrl.eventCustom.emit("changeNickSuccess", _nick);
                GCtrl.GLUtils.showTips("修改成功");
                this.onClickBack();
            }
        });
    }

}
